***********************************
***********************************
*****  REPLICATION FILE FOR: ******
***  MY HISTORY OR OUR HISTORY? ***
***********************************
***********************************

* ========================================================================= *
* - Script: Analysis for Online Appendix (and Dataverse Supplementary Tables)
* - Author: Nicholas Haas (nick.haas@ps.au.dk) 
*           Emmy Lindstam (emmy.lindstam@ie.edu)
* ========================================================================= *

*Set Working Directory*
cd "DIRECTORY/REPLICATION FILES/REPLICATION_PUBLIC"

*Load data*
use Data/DataforAnalysis.dta, clear

*Install packages*
ssc install ietoolkit
ssc install splitvallabels
ssc install catplot

******************************************
*Table A1: Summary Statistics and Balance*
******************************************
iebaltab Gender_N Age Rel_N States1 States2 States3 States4 Lowcaste_N city EducationHigh BJPvote Comps1 Comps2 Comps3 GroupCon, grpvar(Treat) control(1) savetex("Output/Appendix/TableA1.tex") format(%9.2f) star(0.05 0.01 0.001) rowvarlabels replace

***************************************************************************
*Figure C6: Demographic Correlates of Prototypicality (Control Group Only)*
***************************************************************************

preserve
est clear

regress mech1 i.Gender i.Caste i.EducationHigh i.city c.Age i.State if Treat==1

estimates store Typ_NoC

regress mech2 i.Gender i.Caste i.EducationHigh i.city c.Age i.State if Treat==1

estimates store Sim_NoC

regress mech1 i.Gender i.Caste i.EducationHigh i.city c.Age i.State c.GroupCon if Treat==1

estimates store Typ_C

regress mech2 i.Gender i.Caste i.EducationHigh i.city c.Age i.State c.GroupCon if Treat==1

estimates store Sim_C

label var GroupCon "Group Consciousness"
label var Age "Age"

coefplot (Typ_NoC, label(Typical Indian)) (Sim_NoC, label(Similar Other Indians)), bylabel(Excluding Consciousness)   ///
       || (Typ_C)           (Sim_C)         , bylabel(Including Consciousness)  ///
       ||, drop(_cons) xline(0) byopts(xrescale) legend(title("{bf: Prototypicality Measure (1-5)}", size(small))) ///
	   levels(95 90) xline(0, lpattern(dash)) citop scheme(s1color)
gr_edit .plotregion1.subtitle[1].style.editstyle fillcolor(none) editcopy
graph export "Output/Appendix/FigureC6.pdf", as(pdf) replace

*Export results*
tab Gender, gen(gender)
tab Caste, gen(caste)
tab EducationHigh, gen(educhigh)
tab city, gen(Cit)

regress mech1 gender2 caste2 educhigh2 Cit2 Age States2 States3 States4 if Treat==1
estadd scalar n = e(N)
estimates store Typ_NoC2
regress mech2 gender2 caste2 educhigh2 Cit2 Age States2 States3 States4 if Treat==1
estadd scalar n = e(N)
estimates store Sim_NoC2
regress mech1 gender2 caste2 educhigh2 Cit2 Age States2 States3 States4 GroupCon if Treat==1
estadd scalar n = e(N)
estimates store Typ_C2
regress mech2 gender2 caste2 educhigh2 Cit2 Age States2 States3 States4 GroupCon if Treat==1
estadd scalar n = e(N)
estimates store Sim_C2

esttab Typ_NoC2 Sim_NoC2 Typ_C2 Sim_C2 using "Output/Appendix/Table8_SuppAppendix.tex", replace  ///
cells(b(fmt(%9.2f) star) se(par fmt(%9.2f))) style(tex) ///
stats(n r2_a, labels("N" "Adjusted R^{2}") ///
fmt(%9.0f %9.2f)) ///
starlevels(* .10 ** .05 *** .01) ///
keep(gender2 caste2 educhigh2 Cit2 Age States2 States3 States4 GroupCon) /// 
order(gender2 caste2 educhigh2 Cit2 Age States2 States3 States4 GroupCon) /// 
varlabels (gender2 "Female" caste2 "Low Caste" educhigh2 "Above 11th Grade Education" Cit2 "Large City" Age "Age" States2 "Uttar Pradesh" States3 "Gujarat" States4 "Maharashtra" GroupCon "Group Consciousness") ///
mlabels(none) collabels(none)	

restore
***********************************************************************************
*Table C12: Demographic Predictors of Prototypicality and Treatment (Muslims Only)*
***********************************************************************************
*Create variables*
tab Treat, gen(Treat)
gen CasteTreat1=Caste*Treat2
gen CasteTreat2=Caste*Treat3

gen AgeTreat1=Age*Treat2
gen AgeTreat2=Age*Treat3

gen cityTreat1=city*Treat2
gen cityTreat2=city*Treat3

*Run regressions*
reg mech1 Treat2 Treat3 Caste CasteTreat1 CasteTreat2 if Religion==2
estadd scalar n = e(N)
est store Typ_CasteM

reg mech2 Treat2 Treat3 Caste CasteTreat1 CasteTreat2 if Religion==2
estadd scalar n = e(N)
est store Sim_CasteM

reg mech1 Treat2 Treat3 Age AgeTreat1 AgeTreat2 if Religion==2
estadd scalar n = e(N)
est store TypAge_M

reg mech2 Treat2 Treat3 Age AgeTreat1 AgeTreat2 if Religion==2
estadd scalar n = e(N)
est store SimAge_M

reg mech1 Treat2 Treat3 city cityTreat1 cityTreat2 if Religion==2
estadd scalar n = e(N)
est store TypCity_M

reg mech2 Treat2 Treat3 city cityTreat1 cityTreat2 if Religion==2
estadd scalar n = e(N)
est store SimCity_M

*Export results*
esttab Typ_CasteM Sim_CasteM TypAge_M SimAge_M TypCity_M SimCity_M using "Output/Appendix/TableC12.tex", replace  ///
cells(b(fmt(%9.2f) star) se(par fmt(%9.2f))) style(tex) ///
stats(n r2_a, labels("N" "Adjusted R^{2}") ///
fmt(%9.0f %9.2f)) ///
starlevels(* .10 ** .05 *** .01) ///
keep(Treat2 Treat3 Caste CasteTreat1 CasteTreat2 Age AgeTreat1 AgeTreat2 city cityTreat1 cityTreat2) /// 
order(Treat2 Treat3 Caste CasteTreat1 CasteTreat2 Age AgeTreat1 AgeTreat2 city cityTreat1 cityTreat2) /// 
varlabels (Treat2 "Exclusive Trt" Treat3 "Inclusive Trt" Caste "Low Caste" CasteTreat1 "Low Caste X Excl" CasteTreat2 "Low Caste X Incl" Age "Age" AgeTreat1 "Age X Excl" AgeTreat2 "Age X Incl" city "Reside Large City" cityTreat1 "City X Excl" cityTreat2  "City X Incl") ///
mlabels(none) collabels(none)	

**********************************************************************************
*Table C13: Demographic Predictors of Prototypicality and Treatment (Hindus Only)*
**********************************************************************************

*Run regressions*
reg mech1 Treat2 Treat3 Caste CasteTreat1 CasteTreat2 if Religion==1
estadd scalar n = e(N)
est store Typ_CasteH

reg mech2 Treat2 Treat3 Caste CasteTreat1 CasteTreat2 if Religion==1
estadd scalar n = e(N)
est store Sim_CasteH

reg mech1 Treat2 Treat3 Age AgeTreat1 AgeTreat2 if Religion==1
estadd scalar n = e(N)
est store TypAge_H

reg mech2 Treat2 Treat3 Age AgeTreat1 AgeTreat2 if Religion==1
estadd scalar n = e(N)
est store SimAge_H

reg mech1 Treat2 Treat3 city cityTreat1 cityTreat2 if Religion==1
estadd scalar n = e(N)
est store TypCity_H

reg mech2 Treat2 Treat3 city cityTreat1 cityTreat2 if Religion==1
estadd scalar n = e(N)
est store SimCity_H

*Export results*
esttab Typ_CasteH Sim_CasteH TypAge_H SimAge_H TypCity_H SimCity_H using "Output/Appendix/TableC13.tex", replace  ///
cells(b(fmt(%9.2f) star) se(par fmt(%9.2f))) style(tex) ///
stats(n r2_a, labels("N" "Adjusted R^{2}") ///
fmt(%9.0f %9.2f)) ///
starlevels(* .10 ** .05 *** .01) ///
keep(Treat2 Treat3 Caste CasteTreat1 CasteTreat2 Age AgeTreat1 AgeTreat2 city cityTreat1 cityTreat2) /// 
order(Treat2 Treat3 Caste CasteTreat1 CasteTreat2 Age AgeTreat1 AgeTreat2 city cityTreat1 cityTreat2) /// 
varlabels (Treat2 "Exclusive Trt" Treat3 "Inclusive Trt" Caste "Low Caste" CasteTreat1 "Low Caste X Excl" CasteTreat2 "Low Caste X Incl" Age "Age" AgeTreat1 "Age X Excl" AgeTreat2 "Age X Incl" city "Reside Large City" cityTreat1 "City X Excl" cityTreat2  "City X Incl") ///
mlabels(none) collabels(none)	

**********************************************************************************
***********Table C14: Group Consciousness, Treatment, & Prototypicality***********
**********************************************************************************

*Create variables*
gen Con1=GroupCon*Treat2
gen Con2=GroupCon*Treat3
egen Prot_avg=rowmean(mech1 mech2)

*Run regressions*
reg Prot_avg Treat2 Treat3 GroupCon Con1 Con2 if Religion==1
estadd scalar n = e(N)
est store Ovr_H

reg Prot_avg Treat2 Treat3 GroupCon Con1 Con2 if Religion==2
estadd scalar n = e(N)
est store Ovr_M

reg mech1 Treat2 Treat3 GroupCon Con1 Con2 if Religion==1
estadd scalar n = e(N)
est store TypCon_H

reg mech1 Treat2 Treat3 GroupCon Con1 Con2 if Religion==2
estadd scalar n = e(N)
est store TypCon_M

reg mech2 Treat2 Treat3 GroupCon Con1 Con2 if Religion==1
estadd scalar n = e(N)
est store SimCon_H

reg mech2 Treat2 Treat3 GroupCon Con1 Con2 if Religion==2
estadd scalar n = e(N)
est store SimCon_M

esttab Ovr_H Ovr_M TypCon_H TypCon_M SimCon_H SimCon_M using "Output/Appendix/TableC14.tex", replace  ///
cells(b(fmt(%9.2f) star) se(par fmt(%9.2f))) style(tex) ///
stats(n r2_a, labels("N" "Adjusted R^{2}") ///
fmt(%9.0f %9.2f)) ///
starlevels(* .10 ** .05 *** .01) ///
keep(Treat2 Treat3 GroupCon Con1 Con2) /// 
order(Treat2 Treat3 GroupCon Con1 Con2) /// 
varlabels (Treat2 "Exclusive Trt" Treat3 "Inclusive Trt" GroupCon "Religious Group Consciousness" Con1 "Consciousness X Excl" Con2 "Consciousness X Incl") ///
mlabels(none) collabels(none)	

**********************************************************************************************
***********Table C15: Relative Importance of Religion, Treatment, & Prototypicality***********
**********************************************************************************************

*Operationalization 1: fraction of times chose extreme answer (1 or 5) by identity category*

gen Rich=1 if Group_Common_1==1 | Group_Common_1==5
replace Rich=0 if Rich!=1 & Group_Common_1!=.

gen Poor=1 if Group_Common_2==1 | Group_Common_2==5
replace Poor=0 if Poor!=1 & Group_Common_2!=.

gen Hind=1 if Group_Common_3==1 | Group_Common_3==5
replace Hind=0 if Hind!=1 & Group_Common_3!=.

gen Mus=1 if Group_Common_4==1 | Group_Common_4==5
replace Mus=0 if Mus!=1 & Group_Common_4!=.

gen Dal=1 if Group_Common_6==1 | Group_Common_6==5
replace Dal=0 if Dal!=1 & Group_Common_6!=.

gen BJP=1 if Group_Common_7==1 | Group_Common_7==5
replace BJP=0 if BJP!=1 & Group_Common_7!=.

gen Cong=1 if Group_Common_8==1 | Group_Common_8==5
replace Cong=0 if Cong!=1 & Group_Common_8!=.

*Create average by category. We limit religious affiliations to the ones under study here, that is we consider feelings towards Hindus and Muslims.*
egen WealthAvg=rowmean(Rich Poor)
egen RelAvg=rowmean(Hind Mus)
egen CasteAvg=rowmean(Dal)
egen PartyAvg=rowmean(BJP Cong)

*Create indicator equal to one if the fraction for religion is greater than or equal to the fractions for all other categories: wealth, caste, and political party*
gen RelExt=1 if (RelAvg>=WealthAvg) & (RelAvg>=CasteAvg) & (RelAvg>=PartyAvg) & RelAvg!=0
replace RelExt=0 if RelExt!=1 & RelAvg!=. & WealthAvg!=. & CasteAvg!=. & PartyAvg!=.

*Create variables for regression*
gen RelExtTreat1=RelExt*Treat2
gen RelExtTreat2=RelExt*Treat3

*Run regressions*
reg Prot_avg Treat2 Treat3 RelExt RelExtTreat1 RelExtTreat2 if Religion==1
estadd scalar n = e(N)
est store Ovr_HRel

reg Prot_avg Treat2 Treat3 RelExt RelExtTreat1 RelExtTreat2 if Religion==2
estadd scalar n = e(N)
est store Ovr_MRel

reg mech1 Treat2 Treat3 RelExt RelExtTreat1 RelExtTreat2 if Religion==1
estadd scalar n = e(N)
est store Typ_HRel

reg mech1 Treat2 Treat3 RelExt RelExtTreat1 RelExtTreat2 if Religion==2
estadd scalar n = e(N)
est store Typ_MRel

reg mech2 Treat2 Treat3 RelExt RelExtTreat1 RelExtTreat2 if Religion==1
estadd scalar n = e(N)
est store Sim_HRel

reg mech2 Treat2 Treat3 RelExt RelExtTreat1 RelExtTreat2 if Religion==2
estadd scalar n = e(N)
est store Sim_MRel

esttab Ovr_HRel Ovr_MRel Typ_HRel Typ_MRel Sim_HRel Sim_MRel using "Output/Appendix/TableC15.tex", replace  ///
cells(b(fmt(%9.2f) star) se(par fmt(%9.2f))) style(tex) ///
stats(n r2_a, labels("N" "Adjusted R^{2}") ///
fmt(%9.0f %9.2f)) ///
starlevels(* .10 ** .05 *** .01) ///
keep(Treat2 Treat3 RelExt RelExtTreat1 RelExtTreat2) /// 
order(Treat2 Treat3 RelExt RelExtTreat1 RelExtTreat2) /// 
varlabels (Treat2 "Exclusive Trt" Treat3 "Inclusive Trt" RelExt "Prioritizes Religious Identity" RelExtTreat1 "Prioritizes X Excl" RelExtTreat2 "Prioritizes X Incl") ///
mlabels(none) collabels(none)	

**********************************************************************************************
*******************Figure C7: Relative Import Given to Identity Categories********************
**********************************************************************************************

preserve
keep Group_Common_1 Group_Common_2 Group_Common_3 Group_Common_4 Group_Common_5 Group_Common_6 Group_Common_7 Group_Common_8 ID 
reshape long Group_, i(ID) j(Group) string

ren Group_ Answer
recode Answer (1=2) (2=1) (3=0) (4=1) (5=2)

label define Answer_l 0 "Neither easier nor harder" 1 "Easier/harder" 2 "A lot harder/easier"
label values Answer Answer_l

encode Group, gen(Topic)
label define Groupl 1 "Rich" 2 "Poor" 3 "Hindu"  4 "Muslim" 5 "Christian" 6 "Dalit"  7 "BJP" 8 "Congress" 
label values Topic Groupl

splitvallabels Answer
catplot Topic Answer, ///
percent(Topic) ///
l1title(It would be __ to get along with a neighbor from [Group], size(small)) ///
var1opts(label(labsize(small))) ///
var2opts(label(labsize(small))) ///
ytitle("Percent of Respondents (by Target Group)", size(small)) ///
blabel(bar, format(%4.1f) size(vsmall)) yscale(r(0,55)) ///
intensity(25) ///
graphregion(fcolor(white) icolor(white) lcolor (white) ilcolor(white) ifcolor(white)) scheme(s1color)
graph export "Output/Appendix/FigureC7.pdf", as(pdf) replace
restore


**********************************************************************************************
*******************Figure C10: Years of BJP Education, Overall and by State*******************
**********************************************************************************************
*Below, we share how we estimated respondents' years of education under BJP government in our exploratory analysis. We take an individual's state of residence as the location where they obtained their education. 

*Year of birth*
gen YearBorn=2021 - Age

*First year in public education system: we assume age 6 (first year of compulsory education)*
gen Firstyr=(YearBorn + 6) if Education!=0

*Proxy for years of education*
gen Yearsed=Education

*Last year of education*
gen Lastyr=Firstyr + Yearsed
replace Lastyr=2021 if Lastyr>=2021

*Source for information about BJP/BJP-coalition control of state government by year: 
*Trivedi Center for Political Data at Ashoka University Lok Dhaba, accessible here: https://lokdhaba.ashoka.edu.in/*

*Maximum proxy for years of education in dataset: 17*
gen yr_First=(YearBorn + 6) if Education!=0
gen yr_Second=Firstyr+1 if Education>1
gen yr_Third=Firstyr+2 if Education>2
gen yr_Fourth=Firstyr+3 if Education>3
gen yr_Fifth=Firstyr+4 if Education>4
gen yr_Sixth=Firstyr+5 if Education>5
gen yr_Seventh=Firstyr+6 if Education>6
gen yr_Eighth=Firstyr+7 if Education>7
gen yr_Ninth=Firstyr+8 if Education>8
gen yr_Tenth=Firstyr+9 if Education>9
gen yr_Eleventh=Firstyr+10 if Education>10
gen yr_Twelfth=Firstyr+11 if Education>11
gen yr_Thirteenth=Firstyr+12 if Education>12
gen yr_Fourtheenth=Firstyr+13 if Education>13
gen yr_Fifteenth=Firstyr+14 if Education>14
gen yr_Sixtheenth=Firstyr+15 if Education>15
gen yr_Seventheenth=Firstyr+16 if Education>16

**************************
*Gujarat*****************
*************************
*https://lokdhaba.ashoka.edu.in/data-vis?et=AE&seg=&st=Gujarat&viz=seatShareChart

*Year of shift to BJP in Gujarat: 1995. They earn a plurality of vote for first time, as well as majority (66.5%), and have their first chief minister. From that period on, they retain their majority in every subsequent election*

*Coding:*
*Prior to 1995: INC/coded as not BJP*
*1995-present: BJP*
foreach var in yr_First yr_Second yr_Third yr_Fourth yr_Fifth yr_Sixth yr_Seventh yr_Eighth yr_Ninth yr_Tenth yr_Eleventh yr_Twelfth yr_Thirteenth yr_Fourtheenth yr_Fifteenth yr_Sixtheenth yr_Seventheenth {
replace `var'=. if `var'>2021 & State==3
replace `var'=1 if `var'>=1995 & `var'!=. & State==3
replace `var'=0 if `var'<1995 & `var'!=. & `var'!=1 & State==3
}

*************************
*Maharashtra*************
*************************
*https://lokdhaba.ashoka.edu.in/data-vis?et=AE&seg=&st=Maharashtra&viz=seatShareChart

*Year of shift to BJP/Shiv Sena in Maharashtra: 1995. They have plurality for first time, and their first chief minister from 1995-1999*
*Shift back to INC/NCP in 1999, they win plurality and hold onto chief minister position until 2014*
*From 2014-present, BJP/Shiv Sena in control, with majority of seats and chief minister position* 

*Coding:*
*Prior to 1995: INC/coded as not BJP*
*1995-1999: SS/BJP*
*1999-2014: INC/NCP*
*2014-present: SS/BJP*

foreach var in yr_First yr_Second yr_Third yr_Fourth yr_Fifth yr_Sixth yr_Seventh yr_Eighth yr_Ninth yr_Tenth yr_Eleventh yr_Twelfth yr_Thirteenth yr_Fourtheenth yr_Fifteenth yr_Sixtheenth yr_Seventheenth {
replace `var'=. if `var'>2021 & State==4
replace `var'=1 if ((`var'>=1995 & `var'<1999) | (`var'>=2014))  & `var'!=. & State==4
replace `var'=0 if ((`var'<1995) | (`var'>=1999 & `var'<2014)) & `var'!=. & `var'!=1 & State==4
}

*************************
*UP**********************
*************************

*https://lokdhaba.ashoka.edu.in/data-vis?et=AE&seg=&st=Uttar_Pradesh&viz=seatShareChart*

*Year of shift to BJP in UP is 1991, when they win a majority. However, they only retain power for short time.

*Coding:*
*Prior to 1991: INC/coded as not BJP*
*1991-1993:BJP*
*1993-1997:BSP/SP (coded as not BJP)*
*1997-2002: BJP*
*2002-2017: BSP/SP (coded as not BJP)*
*2017-present: BJP*

foreach var in yr_First yr_Second yr_Third yr_Fourth yr_Fifth yr_Sixth yr_Seventh yr_Eighth yr_Ninth yr_Tenth yr_Eleventh yr_Twelfth yr_Thirteenth yr_Fourtheenth yr_Fifteenth yr_Sixtheenth yr_Seventheenth {
replace `var'=. if `var'>2021 & State==2
replace `var'=1 if ((`var'>=1991 & `var'<1993) | (`var'>=1997 & `var'<2002) | (`var'>=2017))  & `var'!=. & State==2
replace `var'=0 if ((`var'<1991) | (`var'>=1993 & `var'<1997) | (`var'>=2002 & `var'<2017)) & `var'!=. & `var'!=1 & State==2
}

****************************
*Delhi**********************
****************************

*https://lokdhaba.ashoka.edu.in/data-vis?et=AE&seg=&st=Delhi&viz=seatShareChart*

*Coding:*
*Prior to 1993: INC/coded as not BJP*
*1993-1998: BJP*
*1998-2013: INC*
*2013-present: AAAP (coded as not BJP)*

foreach var in yr_First yr_Second yr_Third yr_Fourth yr_Fifth yr_Sixth yr_Seventh yr_Eighth yr_Ninth yr_Tenth yr_Eleventh yr_Twelfth yr_Thirteenth yr_Fourtheenth yr_Fifteenth yr_Sixtheenth yr_Seventheenth {
replace `var'=. if `var'>2021 & State==1
replace `var'=1 if ((`var'>=1993 & `var'<1998))  & `var'!=. & State==1
replace `var'=0 if ((`var'<1993) | (`var'>=1998)) & `var'!=. & `var'!=1 & State==1
}

********************************
*Years BJP**********************
********************************

egen Years_BJP=rowtotal(yr_First yr_Second yr_Third yr_Fourth yr_Fifth yr_Sixth yr_Seventh yr_Eighth yr_Ninth yr_Tenth yr_Eleventh yr_Twelfth yr_Thirteenth yr_Fourtheenth yr_Fifteenth yr_Sixtheenth yr_Seventheenth)

***********Density Plot************
kdensity Years_BJP, generate(x0  d0)

forvalues i=1/4 {
capture drop x`i' d`i'
kdensity Years_BJP if States`i'==1, generate(x`i'  d`i')
}

gen zero = 0
twoway rarea d0 zero x0, lcolor("black%70") lwidth(*1.9) fcolor(none) ///
  ||  rarea d1 zero x1, lcolor("orange%50") fcolor(none) ///
  ||  rarea d2 zero x2, lcolor("green%50") fcolor(none) ///
  ||  rarea d3 zero x3, lcolor("blue%50") fcolor(none) ///
  ||  rarea d4 zero x4, lcolor("purple%50") fcolor(none) ///
  title("") fcolor(none) ///
		xscale(range(0 16)) ///
	xlab(0 "0" 4 "4" 8 "8" 12 "12" 16 "16", labsize(vsmall))  ///
 ytitle("Smoothed density") xtitle("Estimated Years of Education under BJP") ///
 legend(ring(0) pos(2) col(1) order(1 "Overall" 2 "Delhi" 3 "Uttar Pradesh" 4 "Gujarat" 5 "Maharashtra")) scheme(s1color) 
graph export "Output/Appendix/FigureC10.pdf", as(pdf) replace


*****************************************************************************************************************
*******************Figure C11: Treatment Effects by Years of BJP Education, Hindus and Muslims*******************
*****************************************************************************************************************

*Plotting Treatment Effects by Years of BJP Education*

*Control variable: attended at least some public school vs. not
tab SchoolType, gen(School)
gen GovSchool=1 if School2==1 | School3==1  | School7==1 | School8==1 | School9==1 | School10==1 
replace GovSchool=0 if School1==1 | School4==1  | School11==1 

preserve
*To create enough observations in each bin, we recode to have the detailed categories: 0, 1-4, 5-6, 7-12, and 13+*
replace Years_BJP=16 if Years_BJP==17
replace Years_BJP=9 if Years_BJP==8 | Years_BJP==7
tab Years_BJP

*****Muslims*****
label var WillingR "Willingness to Lead"

est clear
mat D = ., . ,.,.,., . ,.,.

local i = 1
foreach var in WillingR { 
mat CMAT = ., . ,.,.,., . ,.,.
mat DMAT = ., . ,.,.,., . ,.,.
forvalues bw = 0(4)16 {
local lab_var: variable label `var'	

 areg `var' i.Treat c.Yearsed c.Age i.GovSchool if Years_BJP<=`bw' & Years_BJP>(`bw' - 4) & Religion==2, absorb(State)
		mat A = r(table)
		mat B1 = A[1,2]
		mat B2 = A[1,3]
		mat ll1 = A[5,2]
		mat ll2 = A[5,3]
		mat ul1 = A[6,2]
		mat ul2 = A[6,3] 
		mat rownames B1 = "`var'"
		mat rownames B2 = "`var'"
	mat CMAT = nullmat(CMAT) \ B1, ll1, ul1, `bw', B2, ll2, ul2, `bw'
	local ++i
		}

	matlist CMAT
	*Adding distance between treatments
	
	*Exclusive
	mat CMAT[2,4]=-0.25
	mat CMAT[3,4]=3.75
	mat CMAT[4,4]=7.75
	mat CMAT[5,4]=11.75
	mat CMAT[6,4]=15.75
	
	*Inclusive
	mat CMAT[2,8]=0.25
	mat CMAT[3,8]=4.25
	mat CMAT[4,8]=8.25
	mat CMAT[5,8]=12.25
	mat CMAT[6,8]=16.25
	matlist CMAT
	svmat CMAT
	
	twoway 	(rspike CMAT3 CMAT2 CMAT4) ///
		(scatter CMAT1 CMAT4, msize(small)) ///
		(rspike CMAT7 CMAT6 CMAT8) ///
		(scatter CMAT5 CMAT8, msize(small)) ///
		, yline(0, lwidth(medium) lpattern(dash)) ///
		xtitle("Estimated Years of Education under BJP") ytitle("Treatment effects") ///
		xlab(0 "0" 4 "1-4" 8 "5-6" 12 "7-12" 16 "13+", labsize(vsmall))  ///
		ylab(-1 "-1" -.5 "-.5" 0 "0" .5 ".5" 1 "1", labsize(vsmall))  ///
		scheme(s1color)  ///
		xscale(range(-0.5 16.5)) ///
		yscale(range(-1.5 1.5)) ///
		legend(order(1 "Exclusive Treatment" 3 "Inclusive Treatment" 2 " " 4 " ")) legend(size(small)) title("`lab_var': Muslims", size(medium)) 
    gr_edit legend.Edit , style(rows(1)) style(cols(0)) keepstyles 
	gr_edit legend.plotregion1.key[3].DragBy 0 -85.46696774427004
	gr_edit legend.plotregion1.key[4].DragBy -.1167269074781724 -47.76417662882189
	gr_edit legend.style.editstyle boxstyle(linestyle(width(none))) editcopy
	gr_edit legend.DragBy .233453814956339 4.785803206604876
	graph save "Output/Appendix/FigureC11_A.gph", replace
	drop CMAT*
mat D = nullmat(D) \ CMAT
}

*****Hindus*****
est clear
mat D = ., . ,.,.,., . ,.,.

local i = 1
foreach var in WillingR { 
mat CMAT = ., . ,.,.,., . ,.,.
mat DMAT = ., . ,.,.,., . ,.,.
forvalues bw = 0(4)16 {
local lab_var: variable label `var'	

 areg `var' i.Treat c.Yearsed c.Age i.GovSchool if Years_BJP<=`bw' & Years_BJP>(`bw' - 4) & Religion==1, absorb(State)
		mat A = r(table)
		mat B1 = A[1,2]
		mat B2 = A[1,3]
		mat ll1 = A[5,2]
		mat ll2 = A[5,3]
		mat ul1 = A[6,2]
		mat ul2 = A[6,3] 
		mat rownames B1 = "`var'"
		mat rownames B2 = "`var'"
	mat CMAT = nullmat(CMAT) \ B1, ll1, ul1, `bw', B2, ll2, ul2, `bw'
	local ++i
		}

	matlist CMAT
	*Adding distance between treatments
	
	*Exclusive
	mat CMAT[2,4]=-0.25
	mat CMAT[3,4]=3.75
	mat CMAT[4,4]=7.75
	mat CMAT[5,4]=11.75
	mat CMAT[6,4]=15.75
	
	*Inclusive
	mat CMAT[2,8]=0.25
	mat CMAT[3,8]=4.25
	mat CMAT[4,8]=8.25
	mat CMAT[5,8]=12.25
	mat CMAT[6,8]=16.25
	matlist CMAT
	svmat CMAT
	
	twoway 	(rspike CMAT3 CMAT2 CMAT4) ///
		(scatter CMAT1 CMAT4, msize(small)) ///
		(rspike CMAT7 CMAT6 CMAT8) ///
		(scatter CMAT5 CMAT8, msize(small)) ///
		, yline(0, lwidth(medium) lpattern(dash)) ///
		xtitle("Estimated Years of Education under BJP") ytitle("Treatment effects") ///
		xlab(0 "0" 4 "1-4" 8 "5-6" 12 "7-12" 16 "13+", labsize(vsmall))  ///
		ylab(-1 "-1" -.5 "-.5" 0 "0" .5 ".5" 1 "1", labsize(vsmall))  ///
		scheme(s1color)  ///
		xscale(range(-0.5 16.5)) ///
		yscale(range(-1.5 1.5)) ///
		 legend(off) title("`lab_var': Hindus", size(medium)) 
	graph save "Output/Appendix/FigureC11_B.gph", replace
	drop CMAT*
mat D = nullmat(D) \ CMAT
}

*Combining
grc1leg "Output/Appendix/FigureC11_A.gph" "Output/Appendix/FigureC11_B.gph", scheme(s1color) legendfrom("Output/Appendix/FigureC11_A.gph") imargin(-3 -3 -4 -4) 
graph export "Output/Appendix/FigureC11.pdf", as(pdf) replace
restore

preserve
*Export results*

*Create the same bins*
replace Years_BJP=16 if Years_BJP==17
replace Years_BJP=9 if Years_BJP==8 | Years_BJP==7
tab GovSchool, gen(Gov)

forvalues i=0(4)16 { 
areg WillingR Treat2 Treat3 Yearsed Age Gov2 if Years_BJP<=`i' & Years_BJP>(`i' - 4) & Religion==2, absorb(State)
estadd scalar n = e(N)
estimates store Years_Mus`i' 
}

esttab Years_Mus0 Years_Mus4 Years_Mus8 Years_Mus12 Years_Mus16 using "Output/Appendix/Table9_SuppAppendix.tex", replace  ///
cells(b(fmt(%9.2f) star) se(par fmt(%9.2f))) style(tex) ///
stats(n r2_a, labels("N" "Adjusted R^{2}") ///
fmt(%9.0f %9.2f)) ///
starlevels(* .10 ** .05 *** .01) ///
keep(Treat2 Treat3 Yearsed Age Gov2) /// 
order(Treat2 Treat3 Yearsed Age Gov2) /// 
varlabels (Treat2 "Exclusive Trt" Treat3 "Inclusive Trt" Yearsed "Est. Years of Education" Age "Age" Gov2 "Attended Government School") ///
mlabels(none) collabels(none)	

forvalues i=0(4)16 { 
areg WillingR Treat2 Treat3 Yearsed Age Gov2 if Years_BJP<=`i' & Years_BJP>(`i' - 4) & Religion==1, absorb(State)
estadd scalar n = e(N)
estimates store Years_Hind`i' 
}

esttab Years_Hind0 Years_Hind4 Years_Hind8 Years_Hind12 Years_Hind16 using "Output/Appendix/Table10_SuppAppendix.tex", replace  ///
cells(b(fmt(%9.2f) star) se(par fmt(%9.2f))) style(tex) ///
stats(n r2_a, labels("N" "Adjusted R^{2}") ///
fmt(%9.0f %9.2f)) ///
starlevels(* .10 ** .05 *** .01) ///
keep(Treat2 Treat3 Yearsed Age Gov2) /// 
order(Treat2 Treat3 Yearsed Age Gov2) /// 
varlabels (Treat2 "Exclusive Trt" Treat3 "Inclusive Trt" Yearsed "Est. Years of Education" Age "Age" Gov2 "Attended Government School") ///
mlabels(none) collabels(none)	

restore
